class CommentController < ApplicationController
  before_filter :verify_session
  
  def list
    @comments_pages, @comments = paginate :comments, :per_page => 10 , :order => 'updated_at desc'
     render :action => 'list'
  end
  
  def new
    @comment = Comment.new
  end
  
  def create
    @comment = Comment.new(params[:comment])
    if @comment.save
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end
  
  def destroy
    @comment = Comment.find(params[:id])
    @comment.destroy
    redirect_to :action => 'list'
  end
  
  def new_subcomment
    @subcomment = Subcomment.new
    @subcomment.comment_id = params[:id]
  end
  
  def create_subcomment
    @subcomment = Subcomment.new(params[:subcomment])
    if @subcomment.save
      redirect_to :action => 'list'
    else
      render :action => 'new_subcomment'
    end
  end
end
